﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace BKH.BLL
{
    class KhoaBUO:IBUO<tbl_Khoa>
    {

        HospitalDBDataContext context = new HospitalDBDataContext();
        public bool Insert(tbl_Khoa obj)
        {
            try
            {
                context.tbl_Khoas.InsertOnSubmit(obj);
                context.SubmitChanges();
                return true;

            }
            catch (Exception)
            {

                return false;
            }

        }

        public bool Delete(int id)
        {
            try
            {
                tbl_Khoa obj = context.tbl_Khoas.Where(n => n.id_Ward == id).First<tbl_Khoa>();
                if (obj != null)
                {
                    context.tbl_Khoas.DeleteOnSubmit(obj);
                    context.SubmitChanges();
                    return true;
                }
                else
                {
                    return false;
                }
            }
            catch (Exception)
            {

                return false;
                
            }
        }

        public bool Delete(tbl_Khoa obj)
        {
            throw new NotImplementedException();
        }

        public List<tbl_Khoa> GetAll()
        {
           return context.tbl_Khoas.ToList<tbl_Khoa>();
        }

        public tbl_Khoa GetSingle(int id)
        {
            return context.tbl_Khoas.Where(n => n.id_Ward == id).ToList<tbl_Khoa>().FirstOrDefault();
        }

        public bool Update(int id, tbl_Khoa obj)
        {
            try
            {
                tbl_Khoa khoa = context.tbl_Khoas.Where(n => n.id_Ward == id).ToList<tbl_Khoa>().FirstOrDefault();
                khoa = obj;
                context.SubmitChanges();
                return true;

            }
            catch (Exception)
            {

                return false;
            }
            
        }
    }
}
